#include <bits/stdc++.h>
using namespace std;

void mergesort(int a[], int l, int r) {
  if (l >= r)
    return;
  int mid = (l + r) / 2;  
  mergesort(a, l, mid);
  mergesort(a, mid + 1, r);
  int tmp[10];
  int i = l, j = mid + 1, k = 0;  
  while (i <= mid && j <= r)
    if (a[i] <= a[j])
      tmp[k++] = a[i++];
    else
      tmp[k++] = a[j++];
  while (i <= mid)
    tmp[k++] = a[i++];
  while (j <= r)
    tmp[k++] = a[j++];
  for (int i = l, k = 0; i <= r; i++)
    a[i] = tmp[k++];
}

int main() {
  int a[] = {49, 38, 52, 44, 81, 97, 76, 13, 27, 65};
  mergesort(a, 0, 9);
  for (int i = 0; i < 10; i++)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}

if (l >= r)
  return;
int mid = (l + r) / 2; // ���϶��֣��ݹ���ȥ
mergesort(a, l, mid);
mergesort(a, mid + 1, r);
int i = l, j = mid + 1, k = 0; // �ϲ�����
while (i <= mid && j <= r)
  if (a[i] <= a[j])
    tmp[k++] = a[i++];
  else
    tmp[k++] = a[j++];
while (i <= mid)
  tmp[k++] = a[i++];
while (j <= r)
  tmp[k++] = a[j++];
for (int i = l, j = 0; i <= r; i++)
  a[i] = tmp[j++];
}

int main() {
  int a[] = {49, 38, 52, 44, 81, 97, 76, 13, 27, 65};
  mergesort(a, 0, 9);
  for (int i = 0; i < 10; i++)
    cout << a[i] << " ";
  cout << endl;
  return 0;
}
